package com.lzy.context;

import com.lzy.entity.SysUserEntity;
import com.lzy.security.LoginUser;

import java.util.Objects;

/**
 * 当前用户
 *
 * @author lyw
 * @Date 2023/2/14-下午2:16
 */
public class LocalUser {

  private final static ThreadLocal<LoginUser> loginUser = new ThreadLocal<>();

  public static void set(LoginUser curUser) {
    loginUser.set(curUser);
  }

  public static LoginUser getLoginUser() {
    return loginUser.get();
  }

  public static SysUserEntity me() {
    return getLoginUser().getUser();
  }

  public static void clear() {
    if (!Objects.isNull(loginUser.get())) {
      loginUser.remove();
    }
  }
}
